<?php
/**
 * Created by PhpStorm.
 * User: qilin
 * Date: 2018/1/29
 * Time: 15:31
 */

namespace App\ServiceImpl;


use App\Model\Certificate;
use App\Service\CertificateService;

class CertificateServiceImpl implements CertificateService
{

    public function getCertificateList()
    {
        $data = Certificate::where('certificate_is_verify',1)->orderBy('updated_at','desc')->paginate(15);
        return $data;
        // TODO: Implement getCertificateList() method.
    }

    public function addCertificate($certificate)
    {
        $content  = [$certificate['content-1']];
        if(isset($certificate['content-2'])){
            array_push($content,$certificate['content-2']);
        }
        if(isset($certificate['content-3'])){
            array_push($content,$certificate['content-3']);
        }
        $cert = new Certificate();
        $cert->certificate_name = $certificate['cert-name'];
        $cert->certificate_type = $certificate['cert-type'];
        $cert->certificate_admin_id = $certificate['admin_id'];
        $cert->certificate_date = $certificate['date'];
        $cert->certificate_content= json_encode($content);
        $cert->save();
        // TODO: Implement addCertificate() method.
    }

    public function getVerifyCertificateList()
    {
        $data =Certificate::where('certificate_is_verify','0')->paginate(15);
        return $data;
        // TODO: Implement getVerifyCertificateList() method.
    }

    public function verifyCertificate($id)
    {
        Certificate::where('certificate_id',$id)->update(['certificate_is_verify'=>1]);
        // TODO: Implement verifyCertificate() method.
    }

}